package com.atguigu.dga.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class SpringBeanProvider implements ApplicationContextAware {

    ApplicationContext applicationContext=null;

    //根据需求，根据传递过来的组价名称，和组件类型 返回组件对象
    public  <T>  T getBean(String beanName,Class<T> tClass){
        return applicationContext.getBean(beanName,tClass);
    }



    // 接收公司下发的员工花名册 ,容器启动时，会被容器调用
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext=applicationContext;
    }
}
